class Solution:
    def canPartition(self, nums):
        total_sum = sum(nums)
        if total_sum % 2 != 0:
            return False
        target = total_sum // 2
        dp = [False] * (target + 1)
        dp[0] = True
        for num in nums:
            for j in range(target, num - 1, -1):
                if dp[j - num]:
                    dp[j] = True
        return dp[target]


# 测试代码
if __name__ == "__main__":
    sol = Solution()
    print(sol.canPartition([1, 5, 11, 5]))  # 输出: True
    print(sol.canPartition([1, 2, 3, 5]))  # 输出: False
